/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.company.teleporter;

import com.company.teleporter.application.Application;
import com.company.teleporter.application.DataPath;
import com.company.teleporter.util.FileLookup;
import com.company.teleporter.util.OS;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author home
 */
public class FireFoxApp implements Application {

    private List<DataPath> syncDataPaths = new LinkedList<DataPath>();

    public FireFoxApp() {
        DataPath profile = new DataPath("profile") {

            @Override
            protected String getDefaultPath() {
                if (OS.isWin()) {
                    return "%APPDATA%\\Mozilla\\Firefox\\Profiles\\";
                } else if (OS.isMac()) {
                    return "~/.mozilla/firefox/";
                } else if (OS.isNix()) {
                    return "%APPDATA%\\Mozilla\\Firefox\\Profiles\\";
                }
                return "";
            }
        };

        syncDataPaths.add(profile);
    }

    public void start() {
        String path = null;
        try {
            if (OS.isWin()) {
                path = FileLookup.search("firefox.exe", "%ProgramFiles%\\Mozilla Firefox\\firefox.exe", "%ProgramFiles(x86)%\\Mozilla Firefox\\firefox.exe", "%ProgramW6432%\\Mozilla Firefox\\firefox.exe");
            } else if (OS.isMac()) {
                path = FileLookup.search("firefox.exe", "/usr/lib/firefox", "/usr/lib64/firefox");
            } else if (OS.isNix()) {
                path = FileLookup.search("firefox.exe", "/Applications/Firefox.app");
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FireFoxApp.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }

        try {
            Runtime.getRuntime().exec(path);
        } catch (IOException ex) {
            Logger.getLogger(FireFoxApp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<DataPath> getSyncDataPaths() {
        return syncDataPaths;
    }
}
